package br.com.salao.bean;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.codehaus.jackson.annotate.JsonIgnore;

@Entity
@Table(name="usuario")
@XmlRootElement
public class Usuario implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	@Column(length=40)
	private String nome;
	@Column(length=60)
	private String sobrenome;	
	@Column(length=15)
	private String rg;	
	@Column(length=15)
	private String cpf;
	@Column(length=1)
	private String sexo;
	@Column(length=40)
	private String email;
	@Column(length=2)
	private String ddd1;
	@Column(length=10)
	private String telefone;
	@Column(length=2)
	private String ddd2;
	@Column(length=10)
	private String celular;
	@OneToOne
	@JoinColumn(name = "id_endereco")
	private Endereco endereco;	
	@Temporal(TemporalType.DATE)
	private Date dataNasc;
	@OneToMany
	private Set<Login> login = new HashSet<Login>();
	@Temporal(TemporalType.DATE)
	private Date dataAtual = new Date();
	
	//Local -1:Web - 2:Android
	private int identificador;
	
	public Usuario(){
		endereco = new Endereco();
	}
	
	public String getCpf() {
		return cpf;
	}
	
	public void setCpf(String cpf) {
		this.cpf = cpf;
	}
	
	public Date getDataNasc() {
		return dataNasc;
	}
	
	public void setDataNasc(Date dataNasc) {
		this.dataNasc = dataNasc;
	}
	
	@XmlElement
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	@XmlElement
	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}
	
	@XmlElement
	public String getSobrenome() {
		return sobrenome;
	}

	public void setSobrenome(String sobrenome) {
		this.sobrenome = sobrenome;
	}
	
	@XmlElement
	public String getRg() {
		return rg;
	}

	public void setRg(String rg) {
		this.rg = rg;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@XmlElement
	public String getSexo() {
		return sexo;
	}
	
	public void setSexo(String sexo) {
		this.sexo = sexo;
	}

	public int getIdentificador() {
		return identificador;
	}

	public void setIdentificador(int identificador) {
		this.identificador = identificador;
	}
	
	@XmlElement
	public String getDdd1() {
		return ddd1;
	}

	public void setDdd1(String ddd1) {
		this.ddd1 = ddd1;
	}
	
	@XmlElement
	public String getTelefone() {
		return telefone;
	}

	public void setTelefone(String telefone) {
		this.telefone = telefone;
	}

	@XmlElement
	public String getDdd2() {
		return ddd2;
	}

	public void setDdd2(String ddd2) {
		this.ddd2 = ddd2;
	}
	
	@XmlElement
	public String getCelular() {
		return celular;
	}

	public void setCelular(String celular) {
		this.celular = celular;
	}

	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}

	@XmlElement
	public Endereco getEndereco() {
		return endereco;
	}

	@JsonIgnore 	
	public Set<Login> getLogin() {
		return login;
	}

	public void setLogin(Set<Login> login) {
		this.login = login;
	}

	public Date getDataAtual() {
		return dataAtual;
	}

	public void setDataAtual(Date dataAtual) {
		this.dataAtual = dataAtual;
	}

	public String toSring(Usuario usuario){
		
		StringBuffer sb = new StringBuffer();
		sb.append("Login[");
		sb.append(((Login) usuario.getLogin()).getAcesso());
		sb.append("]");
		sb.append("Usuario[");
		sb.append(usuario.getNome());
		sb.append(" ");
		sb.append(usuario.getSobrenome());
		sb.append("]");
		sb.append("Email[");
		sb.append(usuario.getEmail());
		sb.append("]");
		
		return sb.toString();
	}
	
	
}
